package com.ruitu.mall_98_seller.ui.order;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import com.hjq.permissions.Permission;
import com.ruitu.arad.api.PageModel;
import com.ruitu.arad.base.base_list.BaseRefreshActivity;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;
import com.ruitu.arad.support.view.MyPopWindow;
import com.ruitu.arad.support.widget.progress.ProgressLayout;
import com.ruitu.arad.util.SizeUtils;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.arad.util.UIUtils;
import com.ruitu.mall_98_seller.R;
import com.ruitu.mall_98_seller.base.PhotoCheckActivity;
import com.ruitu.mall_98_seller.dao.bean.AfterSale;
import com.ruitu.mall_98_seller.dao.bean.Express;
import com.ruitu.mall_98_seller.dao.bean.Order;
import com.ruitu.mall_98_seller.dao.bean.OrderFilter;
import com.ruitu.mall_98_seller.mvp.model.OrderModel;
import com.ruitu.mall_98_seller.mvp.presenter.OrderPresenter;
import com.ruitu.mall_98_seller.support.util.ViewUtil;
import com.ruitu.router_module.AppHolder;
import com.ruitu.router_module.Config;
import com.ruitu.router_module.util.AlertUtil;
import com.ruitu.router_module.util.GlideUtil;
import com.ruitu.router_module.util.PermissionUtil;
import com.ruitu.router_module.util.RcvUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import static com.ruitu.mall_98_seller.mvp.presenter.OrderPresenter.TIME_PATTERN;

public class OrderListActivity extends BaseRefreshActivity<OrderPresenter.OrderListP, OrderModel.OrderListM> {
    private static final long duration = 180;
    private TextView tv_status, tv_type, tv_ok;// 订单状态,订单类型,确定筛选
    private ImageView iv_status, iv_type;// 状态和类型的三角形
    private EditText et_log_code;// 发货的快递单号

    private List<Order> orderList = new ArrayList<>();// 订单列表
    private OrderListAdapter adapter;// 订单列表adapter

    private MyPopWindow popF1, popF2;// 弹窗
    private List<OrderFilter> filterList1 = new ArrayList<>();
    private List<OrderFilter> filterList2 = new ArrayList<>();
    private OrderFilter currfilter1, currfilter2;// 当前选择的筛选条件

    private List<Express> expressList = new ArrayList<>();// 快递公司
    private Express currExpress;// 当前选择的快递公司
    ExpressListAdapter expressAdapter;// 快递公司adapter

    private String status;// 订单状态(首页四个状态跳转过来)

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_order_list;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        tv_status = findViewById(R.id.tv_status);
        tv_type = findViewById(R.id.tv_type);
        tv_ok = findViewById(R.id.tv_ok);
        iv_status = findViewById(R.id.iv_status);
        iv_type = findViewById(R.id.iv_type);

        setHeadTitle("我的订单");
        RcvUtils.refreshCompleteDelay(lRecyclerView, null);
        setOnClickListener(tv_status, tv_type, tv_ok);
        alertDialog = new AlertDialog.Builder(this, R.style.Dialog_FS).create();
//        alertDialog2 = new AlertDialog.Builder(this, R.style.Dialog_FS).create();
        expressAdapter = new ExpressListAdapter(OrderListActivity.this);

        try {
            status = getIntent().getExtras().getString("status");
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 生成订单筛选条件数据
        p.genOrderFilter(filterList1, filterList2);
        // 默认选择第一条数据
        currfilter1 = filterList1.get(0);
        currfilter2 = filterList2.get(0);
        // 从首页几个状态跳转过来,需要设置首页的状态
        if (!TextUtils.isEmpty(status)) {
            for (int i = 0; i < filterList1.size(); i++) {
                if (TextUtils.equals(status, filterList1.get(i).getValue())) {
                    currfilter1 = filterList1.get(i);
                    tv_status.setText(currfilter1.getName());
                    break;
                }
            }
        }

        reqData();
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v == tv_status) {// 点击订单状态
            initPopWindow(filterList1, 1);
            popF1.showAsDropDown(tv_status, SizeUtils.dp2px(0), 0);
            iv_status.animate().rotation(180).setDuration(duration).start();
        }
        if (v == tv_type) {// 点击订单类型
            initPopWindow(filterList2, 2);
            popF2.showAsDropDown(tv_type, SizeUtils.dp2px(0), 0);
            iv_type.animate().rotation(180).setDuration(duration).start();
        }
        if (v == tv_ok) {// 确定筛选调条件
//            ToastUtils.showShortSafe(currfilter1.getName() + "   " + currfilter2.getName());
            resetAndReq();
        }
    }

    @Override
    protected void onItemClick(View v, int position) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("order", orderList.get(position));
        startActivity(OrderDetail2Activity.class, bundle);
    }

    @Override
    protected RecyclerView.Adapter initAdapter() {
        adapter = new OrderListAdapter(this);
        return adapter;
    }

    @Override
    protected LRecyclerView findRecyclerView() {
        return findViewById(R.id.rcv_list);
    }

    @Override
    protected void reqFirst() {
        // 下拉刷新,请求第一页的数据
        currfilter1 = filterList1.get(0);
        currfilter2 = filterList2.get(0);
        tv_status.setText("订单状态");
        tv_type.setText("订单类型");
        resetAndReq();
    }

    private int currPage = 1;
    private int totalPage = 1;

    @Override
    protected void reqMore() {
        currPage++;
        if (currPage > totalPage) {
            refreshNoMoreData();
        } else {
            reqData();
        }
    }

    private void reqData() {
        String comId = AppHolder.instance().getUser().getCompany().getId();
        String status = currfilter1.getValue();
        String type = currfilter2.getValue();
        rxList.add(p.reqOrderList(comId, 20, currPage, status, type));
        showProgress();
    }

    @Override
    public void onReqComplete(int code, boolean isOk, Object data) {
        if (code == 1) {// 获取列表
            PageModel<Order> pageModel = (PageModel<Order>) data;
            currPage = pageModel.getCurrentPage();
            totalPage = pageModel.getTotalPage();
            List<Order> newData = pageModel.getDataList();
            orderList.addAll(newData);
            adapter.setDataList(orderList);

            if (isDataEmpty(orderList)) {
                ToastUtils.showShortSafe("没有符合条件的订单");
            }
        } else if (code == 2) {// 通知用户付尾款
            String msg = (String) data;
            onOperateSuccess(msg);
        }
        if (code == 3) {// 获取快递公司
            expressList = (List<Express>) data;
            expressAdapter.setDataList(expressList);
        }
        if (code == 4) {// 发货成功
            String msg = (String) data;
            onOperateSuccess(msg);
        }
        if (code == 5) {// 获取售后详细信息
            showDialog2((AfterSale) data);
        }
        if (code == 6) {// 审批成功
            String msg = (String) data;
            onOperateSuccess(msg);
        }
    }

    // 通知支付尾款,发货 等操作成功后的弹窗提示信息
    private void onOperateSuccess(String msg) {
        UIUtils.showAlertDialog(getSupportFragmentManager(), "温馨提示", msg
                , "好的", "知道了"
                , new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        hideProgress();
                        resetAndReq();
                    }
                }, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        hideProgress();
                        resetAndReq();
                    }
                });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //扫码结果
        IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (intentResult != null) {
            if (intentResult.getContents() == null) {
                ToastUtils.showShortSafe("扫码数据为空");
            } else {
                String result = intentResult.getContents();//返回值
                et_log_code.setText(result);
            }
        }
    }

    // 重置并请求数据
    private void resetAndReq() {
        currPage = 1;
        orderList.clear();
        adapter.setDataList(orderList);
        reqData();
    }

    private View popView;

    private void initPopWindow(final List<OrderFilter> filterList, final int flag) {
        popView = View.inflate(this, R.layout.pop_order_filter, null);

        if (flag == 1) {
            popF1 = new MyPopWindow(popView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            setPopInfo(popF1);

            popF1.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    iv_status.animate().rotation(0).setDuration(duration).start();
                }
            });
        } else if (flag == 2) {
            popF2 = new MyPopWindow(popView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            setPopInfo(popF2);

            popF2.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    iv_type.animate().rotation(0).setDuration(duration).start();
                }
            });
        }

        RecyclerView rcv_list = popView.findViewById(R.id.rcv_list);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        rcv_list.setLayoutManager(manager);
        final AreaListAdapter adapter = new AreaListAdapter(this);
        rcv_list.setAdapter(adapter);
        adapter.setDataList(filterList);
        adapter.setOnItemClickListener(new ListBaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View itemView, int pos) {
                // 点击选择筛选条件
                String name = filterList.get(pos).getName();
                if (flag == 1) {// 筛选状态
                    popF1.dismiss();
                    tv_status.setText(name);
                    currfilter1 = filterList.get(pos);
                    resetAndReq();
                } else if (flag == 2) {// 筛选类型
                    popF2.dismiss();
                    tv_type.setText(name);
                    currfilter2 = filterList.get(pos);
                    resetAndReq();
                }
            }
        });
    }

    private void setPopInfo(MyPopWindow mPop) {
        mPop.setFocusable(true);
//        mPop.setBackgroundDrawable(new ColorDrawable(66000000));
        mPop.setBackgroundDrawable(new ColorDrawable(00000000));
        mPop.setOutsideTouchable(true);
    }

    // 订单列表的adapter
    private class OrderListAdapter extends ListBaseAdapter<Order> {

        public OrderListAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_order_list;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            View item_view = holder.getView(R.id.item_view);
            TextView tv_code = holder.getView(R.id.tv_code);// 订单编号
            TextView tv_time = holder.getView(R.id.tv_time);// 订单时间
            TextView tv_type = holder.getView(R.id.tv_type);// 订单类型
            TextView tv_status = holder.getView(R.id.tv_status);// 订单状态
            TextView tv_name = holder.getView(R.id.tv_name);// 商品名称 订单标题
            TextView tv_price = holder.getView(R.id.tv_price);// 订单货商品价格
            TextView tv_send = holder.getView(R.id.tv_send);// 发货按钮
            TextView tv_notice = holder.getView(R.id.tv_notice);// 通知用户支付尾款
            TextView tv_express = holder.getView(R.id.tv_express);// 售后审批
            ImageView iv_pro = holder.getView(R.id.iv_pro);// 图片

            final Order o = mDataList.get(position);// 小订单对象
            final Order.OrderIn oIn = o.getOrder();// 小订单嵌套的大订单对象

            tv_code.setText("订单编号：" + o.getId());
            tv_time.setText("下单时间：" + (null == o.getCreateTime() ? "1970-01-01 00:00:00" : new SimpleDateFormat(TIME_PATTERN).format(o.getCreateTime())));
            tv_type.setText(p.getType(o.getOrderType()));
            tv_type.setTextColor(getResources().getColor(p.getColorByType(o.getOrderType())));
            tv_status.setText(p.getStatus(o.getOrderStatus(), oIn.getIsPayOver(), oIn.getCollageStatus(), o.getOrderType()));
            tv_name.setText(o.getGoodsName());
            tv_price.setText("共" + o.getQuantity() + "件  实付款:￥" + o.getOrderTotal());
            GlideUtil.loadImg(Config.BASE_URL + o.getGoodsUrl(), iv_pro);

            if ((TextUtils.equals("1", o.getOrderType()) || TextUtils.equals("2", o.getOrderType()))
                    && TextUtils.equals("2", oIn.getIsPayOver())) {
                // 预订或预售 并且已支付订金 显示通知用户支付尾款
                tv_notice.setVisibility(View.VISIBLE);
                tv_send.setVisibility(View.GONE);
                tv_express.setVisibility(View.GONE);
            } else if (TextUtils.equals("2", o.getOrderStatus())) {
                //  已支付 并且拼团状态不是0或者2 显示确认发货
                if (TextUtils.equals("0", oIn.getCollageStatus()) || TextUtils.equals("2", oIn.getCollageStatus())) {
                    tv_notice.setVisibility(View.GONE);
                    tv_send.setVisibility(View.GONE);
                    tv_express.setVisibility(View.GONE);
                } else {
                    tv_notice.setVisibility(View.GONE);
                    tv_send.setVisibility(View.VISIBLE);
                    tv_express.setVisibility(View.GONE);
                }
            } else if (TextUtils.equals("6", o.getOrderStatus())) {
                // 申请售后 显示售后审批
                tv_notice.setVisibility(View.GONE);
                tv_send.setVisibility(View.GONE);
                tv_express.setVisibility(View.VISIBLE);
            } else {
                tv_notice.setVisibility(View.GONE);
                tv_send.setVisibility(View.GONE);
                tv_express.setVisibility(View.GONE);
            }

            // 通知用户支付尾款
            tv_notice.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    UIUtils.showAlertDialog(getSupportFragmentManager(), "温馨提示"
                            , "您是否确定要通知用户支付尾款？"
                            , "确定", "取消"
                            , new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    hideProgress();
                                    rxList.add(p.sendMsg(o.getId(), "2"));
                                    showProgressWithText(true, "处理中,请稍候");
                                }
                            }, null);
                }
            });
            // 发货
            tv_send.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // 发货
                    showDialog(o);
                }
            });
            // 售后审批
            tv_express.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    rxList.add(p.reqAfterSale(o.getId()));// 先请求售后详情,再弹窗展示信息
                    showProgress();
                }
            });
        }
    }

    private AlertDialog alertDialog;
    private View alert_view;//对话框的布局

    // 弹窗
    private void showDialog(final Order currOrder) {
        alert_view = View.inflate(this, R.layout.alert_send_goods, null);
        alertDialog.show();
        AlertUtil.setAlertCenterStyle(alertDialog.getWindow(), alert_view, this);

        currExpress = null;// 每次弹窗,置空已选择的快递公司

        final TextView tv_log_name = alert_view.findViewById(R.id.tv_log_name);// 快递公司
        et_log_code = alert_view.findViewById(R.id.et_log_code);
        final TextView tv_scan = alert_view.findViewById(R.id.tv_scan);// 扫码
        final TextView tv_ok = alert_view.findViewById(R.id.tv_ok);// 确定发货
        tv_log_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popView = View.inflate(OrderListActivity.this, R.layout.pop_order_filter, null);
                final MyPopWindow popLog = new MyPopWindow(popView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                setPopInfo(popLog);
                RecyclerView rcv_list = popView.findViewById(R.id.rcv_list);
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) rcv_list.getLayoutParams();
                params.width = SizeUtils.dp2px(220);
                rcv_list.setLayoutParams(params);
                LinearLayoutManager manager = new LinearLayoutManager(OrderListActivity.this);
                rcv_list.setLayoutManager(manager);
                rcv_list.setAdapter(expressAdapter);
                if (!isDataEmpty(expressList)) {// 有快递数据,直接使用即可
                    expressAdapter.setDataList(expressList);
                } else {// 没有快递数据,先请求
                    rxList.add(p.reqLogList());
                    showProgress();
                }
                expressAdapter.setOnItemClickListener(new ListBaseAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(View itemView, int position) {
                        popLog.dismiss();
                        tv_log_name.setText(expressList.get(position).getName());
                        currExpress = expressList.get(position);
                    }
                });

                popLog.showAsDropDown(tv_log_name, SizeUtils.dp2px(10), 0);
            }
        });
        tv_scan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PermissionUtil.handleSinglePermission(OrderListActivity.this, Permission.CAMERA, "相机"
                        , new PermissionUtil.PermissionListener() {
                            @Override
                            public void onPermissionOk(boolean isOk) {
                                if (isOk) p.startScanCode();
                            }

                            @Override
                            public void onOpenPermissionPage(boolean isOpen) {

                            }
                        });
            }
        });
        tv_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null == currExpress) {// 没有选择快递公司
                    ToastUtils.showShortSafe("请选择快递公司!");
                    return;
                }
                if (ViewUtil.isTvEmpty(et_log_code)) {
                    ToastUtils.showShortSafe("请输入快递单号!");
                    return;
                }
                alertDialog.dismiss();
                showProgressWithText(true, "发货中");
                rxList.add(p.reqSendGoods(currOrder.getId()
                        , currExpress.getCode(), ViewUtil.getTvTxt(et_log_code)));
            }
        });

        alertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
                | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        alertDialog.setCanceledOnTouchOutside(false);
    }

    // 售后审批弹窗
    private void showDialog2(final AfterSale as) {
        alert_view = View.inflate(this, R.layout.alert_after_sale_approve, null);
        alertDialog.show();
        AlertUtil.setAlertCenterStyle(alertDialog.getWindow(), alert_view, this);

        TextView tv_pro_name = alert_view.findViewById(R.id.tv_pro_name);
        TextView tv_pro_status = alert_view.findViewById(R.id.tv_pro_status);
        TextView tv_pro_spec = alert_view.findViewById(R.id.tv_pro_spec);
        TextView tv_pro_num = alert_view.findViewById(R.id.tv_pro_num);
        TextView tv_buyer = alert_view.findViewById(R.id.tv_buyer);
        TextView tv_phone = alert_view.findViewById(R.id.tv_phone);
        TextView tv_reason = alert_view.findViewById(R.id.tv_reason);
        TextView tv_ok = alert_view.findViewById(R.id.tv_ok);
        TextView tv_deny = alert_view.findViewById(R.id.tv_deny);
        TextView tv_cancel = alert_view.findViewById(R.id.tv_cancel);
        ImageView iv_pic1 = alert_view.findViewById(R.id.iv_pic1);
        ImageView iv_pic2 = alert_view.findViewById(R.id.iv_pic2);
        ImageView iv_pic3 = alert_view.findViewById(R.id.iv_pic3);
        LinearLayout ll_imgs = alert_view.findViewById(R.id.ll_imgs);
        RelativeLayout rl_pic = alert_view.findViewById(R.id.rl_pic);

        tv_pro_name.setText(as.getGoodsName());
        tv_pro_status.setText(TextUtils.equals("1", as.getRefundStatus()) ? "已收到商品" : "未收到商品");
        tv_pro_spec.setText(as.getSkuContent());
        tv_pro_num.setText(as.getQuantity());
        tv_buyer.setText(as.getAccountName());
        tv_phone.setText(as.getBuyerPhone());
        tv_reason.setText(as.getRefundReason());

        final List<AfterSale.Img> imgList = as.getImages();
        if (isDataEmpty(imgList)) {
            ll_imgs.setVisibility(View.GONE);
            rl_pic.setVisibility(View.GONE);
        } else {
            ll_imgs.setVisibility(View.VISIBLE);
            rl_pic.setVisibility(View.VISIBLE);
            if (imgList.size() == 1) {
                iv_pic1.setVisibility(View.VISIBLE);
                iv_pic2.setVisibility(View.GONE);
                iv_pic3.setVisibility(View.GONE);
                GlideUtil.loadImg(Config.BASE_URL + imgList.get(0).getUrl(), iv_pic1);
            } else if (imgList.size() == 2) {
                iv_pic1.setVisibility(View.VISIBLE);
                iv_pic2.setVisibility(View.VISIBLE);
                iv_pic3.setVisibility(View.GONE);
                GlideUtil.loadImg(Config.BASE_URL + imgList.get(0).getUrl(), iv_pic1);
                GlideUtil.loadImg(Config.BASE_URL + imgList.get(1).getUrl(), iv_pic2);
            } else if (imgList.size() == 3) {
                iv_pic1.setVisibility(View.VISIBLE);
                iv_pic2.setVisibility(View.VISIBLE);
                iv_pic3.setVisibility(View.VISIBLE);
                GlideUtil.loadImg(Config.BASE_URL + imgList.get(0).getUrl(), iv_pic1);
                GlideUtil.loadImg(Config.BASE_URL + imgList.get(1).getUrl(), iv_pic2);
                GlideUtil.loadImg(Config.BASE_URL + imgList.get(2).getUrl(), iv_pic3);
            } else {
                ll_imgs.setVisibility(View.GONE);
                rl_pic.setVisibility(View.GONE);
            }
        }

        tv_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UIUtils.showAlertDialog(getSupportFragmentManager(), "温馨提示", "是否确认退款？"
                        , "确定", "取消"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                alertDialog.dismiss();
                                rxList.add(p.reqRefund(as.getId(), "0"));// 0 同意 1 拒绝
                                showProgressWithText(true, "处理中");
                            }
                        }, null);
            }
        });
        tv_deny.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UIUtils.showAlertDialog(getSupportFragmentManager(), "温馨提示", "是否拒绝退款？"
                        , "确定", "取消"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                alertDialog.dismiss();
                                rxList.add(p.reqRefund(as.getId(), "1"));// 0 同意 1 拒绝
                                showProgressWithText(true, "处理中");
                            }
                        }, null);
            }
        });
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
            }
        });
        ll_imgs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(OrderListActivity.this, PhotoCheckActivity.class);
                intent.putExtra("position", 0);
                ArrayList<String> imgPaths = new ArrayList<>();
                for (AfterSale.Img i : imgList) {//封装图片路径,传到图片查看页面
                    imgPaths.add(Config.BASE_URL + i.getUrl());
                }
                intent.putExtra("list", imgPaths);
                startActivity(intent);
                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }
        });

        alertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
                | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        alertDialog.setCanceledOnTouchOutside(false);
    }

    // 下拉筛选条件的adapter
    private class AreaListAdapter extends ListBaseAdapter<OrderFilter> {

        public AreaListAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.pop_item_search_list;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            TextView tv_name = holder.getView(R.id.tv_name);
            tv_name.setText(mDataList.get(position).getName());
        }
    }

    // 快递公司的adapter
    protected class ExpressListAdapter extends ListBaseAdapter<Express> {

        public ExpressListAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.pop_item_search_list;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            TextView tv_name = holder.getView(R.id.tv_name);
            tv_name.setText(mDataList.get(position).getName());
        }
    }

    @Override
    protected ProgressLayout findProgressLayout() {
        return null;
    }
}
